﻿using Basic.FormCollect;
using Basic.FormLocalEvent.Model;
using Basic.FormRemoteModel;
using Basic.FormRemoteModel.QueryTable.Model;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;

namespace Basic.FormLocalEvent.Form
{
    [LocalEventName("Add")]
    internal class AddDefMainQueryTable : IEventHandler<FormEvent>
    {
        private readonly IQueryTableCollect _Service;

        public AddDefMainQueryTable ( IQueryTableCollect service )
        {
            this._Service = service;
        }

        public void HandleEvent ( FormEvent data, string eventName )
        {
            if ( data.Form.FormType == FormType.物理表单 )
            {
                _ = this._Service.Add(new PhyQueryTableAdd
                {
                    FormId = data.Form.Id,
                    Show = data.Form.FormName,
                    TableName = data.Form.TableName,
                }, true);
            }
        }
    }
}
